<?php
$node_user =& $node->get('User');
$tag_html = array();
$node_tags =& $node->get('Tags');
if ($node_tags->size() > 0) {
    while ($tag =& $node_tags->getNext()) {
        $tag_html[] = sprintf('<a href="%s" rel="tag">%s</a>', $tag->getLink(), h($tag->getLabel()));
    }
}
?>
<div class="node clearfix">
  <h4 class="nodeSource"><?php echo $node->getSourceHTMLLink();?></h4>
  <h2 class="nodeTitle">
<?php if (!isset($category)) $category =& $node->get('Category');?>
<?php if ($category):?>
<?php   printf('<a href="%s">%s</a>: ', Sabai_URL::get('/', array('category_id' => $category->getId())), h($category->getLabel()));?>
<?php endif;?>
<?php unset($category);?>
    <a href="<?php echo Sabai_URL::get('/node/' . $node->getId());?>"><?php _h($node->get('title'));?></a>
  </h2>
<?php if ($CONFIG->get('useVotingFeature')):?>
  <div class="nodeVote">
    <div class="nodeVoteCount"><span id="xigg-votenode<?php echo $node->getId();?>"><?php echo $node->getVoteCount();?></span></div>
    <div class="nodeVoteText">
<?php   if ($USER->isAuthenticated()):?>
<?php     if (!in_array($node->getId(), $nodes_voted)):?>
<?php       link_to_remote(_('xigg it'), 'xigg-votenode' . $node->getId(), array('base' => '/node/' . $node->getId() . '/voteform'), array('base' => '/node/' . $node->getId() . '/vote', 'params' => array('echo' => 1), 'query' => array($this->helper('Token', 'Vote_submit_' . $node->getId(), true))), array('post' => true, 'replace' => '<span>' . _('xigged') . '</span>', 'failure' => 'xigg-votenodeerror' . $node->getId()));?>
<?php     else:?>
        <span><?php _e('xigged');?></span>
<?php     endif;?>
<?php   else:?>
        <span><?php _e('xigg it');?></span>
<?php   endif;?>
    </div>
    <div id="xigg-votenodeerror<?php echo $node->getId();?>" class="nodeVoteError"></div>
  </div>
<?php endif;?>
  <div class="nodeInfo">
    <div class="nodeInfoPoster"><?php echo $node_user->getHTMLImageLink(32, 32);?></div>
    <div class="nodeInfoDetails">
<?php if ($CONFIG->get('useUpcomingFeature') && $node->isPublished()):?>
<?php   printf(_('%s submitted %s, published <strong>%s</strong>'), $node_user->getHTMLLink(), h($this->helper('XiggAgo', $node->getTimeCreated())), h($this->helper('XiggAgo', $node->get('published'))));?>
<?php else:?>
<?php   printf(_('%s submitted <strong>%s</strong>'), $node_user->getHTMLLink(), h($this->helper('XiggAgo', $node->getTimeCreated())));?>
<?php endif;?>
    <br />
    <span class="nodeInfoTags"><?php _e('Tags: ');?>
<?php if (!empty($tag_html)):?>
<?php   echo implode(', ', $tag_html);?>
<?php endif;?>
    </span>
    </div>
  </div>
  <div class="nodeContent">
<?php if ($source = $node->get('source')):?>
    <div class="nodeBodyScreenshot">
      <a href="<?php echo $source;?>" class="linkbubbler" title="<?php _h($node->get('source_title'));?>"><?php echo $node->getScreenshot();?></a>
    </div>
<?php endif;?>
    <p class="nodeTeaser">
<?php if ($teaser = $node->get('teaser_html')):?>
<?php   echo $teaser;?>&nbsp;<a href="<?php echo Sabai_URL::get('/node/' . $node->getId(), array(), 'nodeBody');?>" title="<?php _e('Read full story');?>"><?php _e('more...');?></a>
<?php else:?>
<?php   echo $node->get('body_html');?>
<?php endif;?>
    </p>
  </div>
  <div class="nodeInnerLinks">
<?php if ($CONFIG->get('useCommentFeature')):?>
    <span class="nodeCommentsLink"><a href="<?php echo Sabai_URL::get('/node/' . $node->getId(), array(), 'nodeComments');?>"><?php printf(_('Comments (%d)'), $node->getCommentCount());?></a></span>
<?php endif;?>
<?php if ($CONFIG->get('useTrackbackFeature')):?>
    <span class="nodeTrackbacksLink"><a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/trackbacktab', array(), 'nodeTrackbacks');?>"><?php printf(_('Trackbacks (%d)'), $node->getTrackbackCount());?></a></span>
<?php endif;?>
<?php if ($CONFIG->get('useVotingFeature')):?>
    <span class="nodeVotesLink"><a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/votetab', array(), 'nodeVotes');?>"><?php printf(_('Votes (%d)'), $node->getVoteCount());?></a></span>
<?php endif;?>
<?php if ($USER->isInRole(array(XIGG_ROLE_ADMIN, XIGG_ROLE_EDITOR))):?>
    |
    <span class="nodeAdminLink">
      <a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/edit');?>"><img src="<?php echo $LAYOUT_URL;?>/images/edit.gif" alt="<?php _e('Edit');?>" alt="<?php _e('Edit this entry');?>" /></a>
      <a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/delete');?>"><img src="<?php echo $LAYOUT_URL;?>/images/delete.gif" alt="<?php _e('Delete');?>" alt="<?php _e('Delete this entry');?>" /></a>
<?php   if(!$node->isPublished()):?>
      <a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/publish');?>"><img src="<?php echo $LAYOUT_URL;?>/images/tick.gif" alt="<?php _e('Popular');?>" alt="<?php _e('Make this entry popular');?>" /></a>
<?php   endif;?>
    </span>
<?php elseif ($USER->isInRole(array(XIGG_ROLE_WRITER))):?>
<?php   if ($node->get('allow_edit') && $node->isOwnedBy($USER)):?>
    |
    <span class="nodeAdminLink">
      <a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/edit');?>"><img src="<?php echo $LAYOUT_URL;?>/images/edit.gif" alt="<?php _e('Edit');?>" alt="<?php _e('Edit this entry');?>" /></a>
    </span>
<?php   endif;?>
<?php elseif ($USER->isInRole(array(XIGG_ROLE_WRITER))):?>
<?php   if (!$node->isPublished() && $node->get('allow_edit') && $node->isOwnedBy($USER)):?>
    |
    <span class="nodeAdminLink">
      <a href="<?php echo Sabai_URL::get('/node/' . $node->getId() . '/edit');?>"><img src="<?php echo $LAYOUT_URL;?>/images/edit.gif" alt="<?php _e('Edit');?>" alt="<?php _e('Edit this entry');?>" /></a>
    </span>
<?php   endif;?>
<?php endif;?>
  </div>
</div>